package com.lagou.pojo;

import java.io.IOException;
import java.io.InputStream;

/**
 * 封装Request类
 */
public class Request {

    private String method;

    private String url;

    private InputStream inputStream;

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public Request(InputStream inputStream) throws IOException {
        int count = 0;
        while (count == 0){
            //获取输入流长度
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);
        String requestString = new String(bytes);
        //拆分各项字符
        String[] split = requestString.split("\n");
        //获取请求头
        String header = split[0];
        String[] headerArray = header.split(" ");
        this.method = headerArray[0];
        this.url = headerArray[1];
        this.inputStream = inputStream;
    }

    public Request() {
    }
}
